const express = require('express');
const router = express.Router();
const productService = require('../service/productService')


router.get('/findAll',(req,res)=>{
    productService.findAll((rows)=>{
        res.json(rows)
    })
})


router.get('/finByName',(req,res)=>{
    let productName = req.query.productName ;
    productService.findByName(productName,(resMsg)=>{
        res.json(resMsg)
    })
})


router.post('/add',(req,res)=>{
    const product = {
        productName:req.body.productName,
        desc:req.body.desc
    }

    productService.add(product,(resMsg)=>{
        res.json(resMsg);
    })
})

router.post('/edit',(req,res)=>{
    const product = {
        productId:req.body.productId,
        productName:req.body.productName,
        desc:req.body.desc
    }

    productService.edit(product,(resMsg)=>{
        res.json(resMsg);
    })
})

router.post('/remove',(req,res)=>{
    const productId = req.body.productId;

    productService.edit(productId,(resMsg)=>{
        res.json(resMsg);
    })
})


module.exports = router;
